<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ include file="../../../../header.jsp"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title></title>
<style>
.required-wrap {
    color: #f00;
    margin-left: -6px;
    margin-right: 1px;
    font-size: 12px;
}
.wrap{margin:30px 30px 10px 30px;}
.wrap .jobcode{margin-top: 20px;float:left;}
.wrap-input{width: 220px; height: 28px;margin-left:40px;}
.wrap-input1{width: 220px; height: 28px;margin-left:18px;}
textarea.ui-input {
    height: 60px;
    width: 220px;
}
</style>

</head>
<body style="align: center;">
	<div style="margin-top: 30px; margin-left: 30px;">
		<form id="manage-form" action=""  enctype="multipart/form-data" >
			<div  class="wrap">
				<span class="required-wrap">*</span><label for="jobcode">职员姓名:</label>
				<input type="text" class="wrap-input ui-input"
					name="personName" id="personName">
			</div>
			<div  class="wrap">
				<span class="required-wrap">*</span><label for="jobcode">所属公司:</label>
				<input type="text" class="wrap-input ui-input"
					name="companyName" id="companyName">
			</div>
			<div  class="wrap">
				<span class="required-wrap">*</span>
				 <label
					for="jobcode">图像名称:</label> 
					<input type="text" class="wrap-input ui-input"
					name="imageName" id="imageName">
			</div>
			<div  class="wrap">
				<span class="required-wrap">*</span><span>选择图片：</span>
                <input id="fileId" type="file"  name="file" onchange="changepic(this)">
                <img  id="files" class="btn_blue" style="width: 400px;height: 200px; border: none;">
           </div>
		</form>
	</div>

<script type="text/javascript">
var api=frameElement.api;
var operate=api.data.operate;
var rowid=api.data.rowid;
var rowdata=api.data.rowdata;
var CallBack=api.data.callback;

$(function(){
	initPopBtns();
})
function initPopBtns() {
	var btnname = "add" == operate ? ["保存", "关闭"] : ["确定", "取消"];
	api.button({
		id: "confirm",
		name: btnname[0],
		focus: true,
		callback: function(e) {
				
			var myform = new FormData();
			myform.append('personName',$("#personName").val());
			myform.append('imageName',$("#imageName").val());
			if(operate=="add"){
				myform.append('file',$("#fileId")[0].files[0]);
				$.ajax({
					url:'/personImage/add',
		            type:'post',
		            data:myform,
		            dataType:'json',
		            cache:true,
		            async:false,
		            contentType:false,
		            processData:false,
					success : function(data) {
						if(data.status==200){
							parent.Public.tips({
								content: "添加图片成功"
							})
							CallBack();
						}else{
							parent.Public.tips({
								type:1,
								content: "添加图片失败:"+data.msg
							})
						}
					}
				});
			}else{
				$.ajax({
					url:encodeURI("personImage/edit"),
					type:"POST",
					data:{
						
					},
					async : false,//同步
					success:function(data){
						if(data.status==200){
							parent.Public.tips({
								content: "修改图片信息成功"
							})
							CallBack();
						}else{
							parent.Public.tips({
								type:1,
								content: "修改图片信息失败:"+data.msg
							})
						}		
					}
				});
			}
		}
	}, {
		id: "cancel",
		name: btnname[1]
	})
}
    
    
    






function changepic(obj){
	
	var url=getObjectURL(obj.files[0]);
	document.getElementById('files').src=url;
}

function getObjectURL(file) {
        var url = null ;
        // 下面函数执行的效果是一样的，只是需要针对不同的浏览器执行不同的 js 函数而已
        if (window.createObjectURL!=undefined) { // basic
            url = window.createObjectURL(file) ;
        } else if (window.URL!=undefined) { // mozilla(firefox)
            url = window.URL.createObjectURL(file) ;
        } else if (window.webkitURL!=undefined) { // webkit or chrome
            url = window.webkitURL.createObjectURL(file) ;
        }
        return url ;
    }

</script>
</body>
</html>